package com.ibiaoke.boss.controller;

import com.ibiaoke.boss.entity.SysUser;
import com.ibiaoke.common.base.BaseController;
import com.ibiaoke.common.base.Page;
import com.ibiaoke.common.response.Res;
import com.ibiaoke.goods.entity.XcxGoods;
import com.ibiaoke.goods.entity.vo.XcxGoodsVO;
import com.ibiaoke.goods.service.XcxGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author Dragon
 * @date 2018/3/21/14:39;
 */
@Controller
public class BossXcxGoodsController extends BaseController{

    @Autowired
    private XcxGoodsService xcxGoodsService;
    /**
     * 商品列表
     */
    @ResponseBody
    @RequestMapping("/listXcxGoods")
    public Res listXcxGoods(XcxGoodsVO xcxGoodsVO, Page page) {
        List<XcxGoods> xcxGoodsList = xcxGoodsService.listXcxGoods(xcxGoodsVO,page);
        return Res.create()
                .addResponse("xcxGoodsList",xcxGoodsList)
                .addResponse("page",page);
    }
    /**
     * 添加商品
     */
    @ResponseBody
    @RequestMapping("/saveXcxGoods")
    public Res saveXcxGoods(XcxGoods xcxGoods) {
        xcxGoodsService.saveXcxGoods(xcxGoods);
        return Res.create();
    }

    /**
     * 根据商品Id获取商品信息
     * @param xcxGoodsId
     * @return
     */
    @ResponseBody
    @RequestMapping("/getXcxGoodsById")
    public Res getXcxGoodsById(Integer xcxGoodsId) {
        XcxGoods xcxGoods =  xcxGoodsService.getXcxGoodsById(xcxGoodsId);
        return Res.create().addResponse("xcxGoods", xcxGoods);
    }

    /**
     * 根据Id修改商品信息
     * @param xcxGoodsVO
     * @return
     */
    @ResponseBody
    @RequestMapping("/updateXcxGoodsInfoById")
    public Res updateXcxGoodsInfoById(XcxGoodsVO xcxGoodsVO) {
        int count = xcxGoodsService.updateGoodsInfoById(xcxGoodsVO);
        return Res.create();
    }

    /**
     * 批量修改商品上下架
     * @param xcxGoodsId
     * @param status
     * @return
     */
    @ResponseBody
    @RequestMapping("/batchUpdateXcxGoodsStatus")
    public Res batchUpdateGoodsStatus(String xcxGoodsId,Integer status){
        int count = xcxGoodsService.batchUpdateGoodsStatus(xcxGoodsId,status);
        return Res.create().addResponse("count",count);
    }

    /**
     * 批量修改商品删除状态
     * @param xcxGoodsId
     * @param delStatus
     * @return
     */
    @ResponseBody
    @RequestMapping("/batchUpdateXcxGoodsDelStatus")
    public Res batchUpdateGoodsDelStatus(String xcxGoodsId,Integer delStatus){
        int count = xcxGoodsService.batchUpdateGoodsDelStatus(xcxGoodsId,delStatus);
        return Res.create().addResponse("count",count);
    }

    /**
     * 根据分类查询商品
     *
     * @param cateId
     * @param shopId
     * @param page   @return
     */
    @ResponseBody
    @RequestMapping("/xcxGoodsList")
    public Res listGoodsByCateId(Integer cateId, Integer shopId, Page page) {
        List<XcxGoods> xcxGoodsList = xcxGoodsService.xcxListGoodsByGoodsClass(cateId, shopId, page);
        return Res.create().addResponse("xcxGoodsList", xcxGoodsList).addResponse("page", page);
    }
}
